package cn.layfolk.daimao.vo.respvo;

import cn.layfolk.daimao.consts.ErrorCodeEnum;
import cn.layfolk.daimao.consts.ResponseCode;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 响应VO
 * @author: panhongtong
 * @create: 2020-04-29 23:14
 **/
@Data
@NoArgsConstructor
public class ResponseVo<T> implements Serializable {
    private int statusCode = 200;
    private String message = "";
    private T data;

    public static ResponseVo ok(Object data) {
        return new ResponseVo(data);
    }

    public static ResponseVo ok(Object data,String message) {
        ResponseVo responseVo = new ResponseVo(data);
        responseVo.setMessage(message);
        return responseVo;
    }

    public static ResponseVo fail() {
        return new ResponseVo(null);
    }

    public static ResponseVo fail(ErrorCodeEnum message) {
        return new ResponseVo(message.getMessage(),message.getStatusCode(),null);
    }


    public static ResponseVo fail(String message) {
        return new ResponseVo(message);
    }

    public static ResponseVo fail(String message, int statusCode) {
        return new ResponseVo(message, statusCode);
    }

    public static ResponseVo failByParam(String message) {
        return new ResponseVo(message, ResponseCode.PARAM_ERROR_CODE.getCode());
    }

    public ResponseVo(T data) {
        super();
        this.data = data;
    }

    public ResponseVo(String message) {
        super();
        this.message = message;
    }

    public ResponseVo(String message, int statusCode) {
        super();
        this.message = message;
        this.statusCode = statusCode;
    }

    public ResponseVo(String message, int statusCode,T data) {
        this.message = message;
        this.statusCode = statusCode;
        this.data = data;
    }

}
